<template>
	<iframe
		class="pdfIframe"
		ref="pdfIframe"
		:src="url"
		frameborder="0"
		style="width: 100%; height: 100%"></iframe>
</template>

<script>
	import { downFile } from '@/api/system/oss';
	export default {
		props: {
			src: {
				required: true,
			},
		},
		data() {
			return {
				url: '',
			};
		},
		created() {
			if (this.src) {
				downFile(this.src)
					.then(res => {
						if (res) {
							this.url = URL.createObjectURL(res);
							this.rendered();
						} else {
							throw new Error();
						}
					})
					.catch(() => {
						this.error();
					});
			}
		},
		mounted() {},
		beforeDestroy() {},
		methods: {
			rendered() {
				this.$emit('rendered');
			},
			error() {
				this.$emit('error');
			},
		},
	};
</script>

<style lang="scss" scoped></style>
